package com.itcast.jobs;

import com.itcast.constant.RedisConstant;
import com.itcast.untils.QiniuUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import redis.clients.jedis.JedisPool;

import java.util.Set;

/**
 * 清理多余图片
 */
@Component("clearImgJob")
public class ClearImgjob {
    @Autowired
    private JedisPool jedisPool;
    public void clearImg(){
    //从jedis中获取两个set集合的数据差
        Set<String> imgs = jedisPool.getResource().sdiff(RedisConstant.SETMEAL_PIC_RESOURCES, RedisConstant.SETMEAL_PIC_DB_RESOURCES);
        if(imgs != null && imgs.size() > 0){
            for(String img:imgs){
                System.out.println("shanchu");
                //调用七牛云的删除工具类
                QiniuUtils.deleteFileFromQiniu(img);
                //从jedis中删除
                jedisPool.getResource().srem(RedisConstant.SETMEAL_PIC_RESOURCES,img);
            }
        }
    }
}
